#pragma once
#include"rb_tree.h"

using namespace std;

namespace ybc
{
	template<class K, class V>
	class map
	{
		struct mapKeyOfT
		{
			const K& operator () (const pair<K, V>& kv)
			{
				return kv.first;
			}
		};
	public:
		typedef typename RBTree<K, pair<const K, V>, mapKeyOfT>::iterator iterator;
		typedef typename RBTree<K, pair<const K, V>, mapKeyOfT>::const_iterator const_iterator;

		iterator begin()
		{
			return _t.begin();
		}

		iterator end()
		{
			return _t.end();
		}

		const_iterator cbegin() const
		{
			return _t.cbegin();
		}

		const_iterator cend() const
		{
			return _t.cend();
		}

		pair<iterator, bool> insert(const pair<K, V>& kv)
		{
			return _t.insert(kv);
		}

		iterator find(const K& key)
		{
			return _t.find(key);
		}

		V& operator [] (const K& key)
		{
			pair<iterator, bool> ret = insert(make_pair(key, V()));
			return ret.first->second;
		}
	private:
		RBTree<K, pair<const K, V>, mapKeyOfT> _t;
	};
}